package com.miyake.dsp.osa.lab.wrapper;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.DecibelSetting;
import com.miyake.dsp.osa.lab.LabUiAnnotation;

@LabUiAnnotation(caption="Decibel")
public class DecibelWrapper extends Calculator {
	public static final String INPUT = "Input";
	public static final String OUTPUT = "Output";
	private DecibelSetting setting;
	
	public DecibelWrapper(DecibelSetting setting) {
		initInput(INPUT);
		initOutput(OUTPUT);
		this.setting = setting;
	}
	
	@Override
	public synchronized void process() {
		double[] lin = this.getInput(INPUT).getRealPart();
		double[] db = new double[lin.length];
		for (int i = 0; i < db.length; i++) {
			if (lin[i] > 0.0) {
				db[i] = 10 * Math.log10(lin[i]);
			}
			else {
				db[i] = setting.getFloor();
			}
		}
		this.setOutput(OUTPUT, new ComplexArray(db));
	}

	@Override
	public Object getSetting() {
		return setting;
	}

}
